package com.amqp.demo.web;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AmqpService {

    @Autowired
    private AmqpTemplate amqpTemplate;

    public void sendMsg(String msg){
        Message s = MessageBuilder.withBody(msg.getBytes()).build();
        //amqpTemplate.send(s);
        //amqpTemplate.send("queue-100",s);
        amqpTemplate.send("ex-100","", s);
    }

    @RabbitListener(queues = "queue-100")
    public void processMessage(String content) {
        System.out.println(content);
    }

}
